package com.lijian.study.neo4j.entity;

import java.util.Objects;

import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.RelationshipId;
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
import org.springframework.data.neo4j.core.schema.TargetNode;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 定义 Person 之间的 KNOWS 关系
 */
@Setter
@Getter
@RelationshipProperties
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Knows {

    @RelationshipId
    @GeneratedValue()
    private Long id;

    private String since; // 比如关系开始的时间

    @TargetNode
    private Person targetPerson;

    // 在Knows类中
    @Override
    public int hashCode() {
        return Objects.hash(since, targetPerson.getId()); // 使用targetPerson的id而不是整个对象
    }

}